package cn.edu.zafu.bigdata.x.sxy;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class DemoSever {
    public static void main(String[] args) throws IOException {
        int prot = 3000; // 服务端端口号
        ServerSocket serverSocket = new ServerSocket(prot);
        System.out.println("Server is running...");

        try{
            while (true){
                Socket clientSocket = serverSocket.accept();
                System.out.println("Client connected");

                BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
                PrintWriter out = new PrintWriter(clientSocket.getOutputStream(),true);

                String inputline;
                while ((inputline = in.readLine()) != null){
                    System.out.println("Client says: "+ inputline);
                    String response = "okay.";
                    out.println(response);
                }
                clientSocket.close();
            }
        }finally {
            serverSocket.close();
        }
    }
}
